//definitiile de metode (corpurile metodelor)
#include "Complex.h"
#include <iostream>
#include <math.h>
Complex:: Complex()
{
    (*this).real=1.0;  //this pointer catre obiectul curent
    (*this).imag=1.0;
}
Complex:: Complex (const Complex *c)
{
    this->real=c->real;
    this->imag=c->imag;
}
Complex::Complex(double real, double imag)
{
    this->real=real;
    this->imag=imag;
}

Complex::~Complex()
{

}
Complex Complex::operator+(Complex z)
{
    double re,im;
    re=this->real + getReal();
    im=this->imag + getImag();
    Complex s = Complex(re,im);
    return s;
}

Complex Complex::operator+(double d)
{
    double re,im;
    re=this->real + d;
    im=this->imag + d;
    Complex s = Complex(re,im);
    return s;
    
}
Complex Complex::operator-(Complex c)
{
    double re,im;
    re=this->real-getReal();
    im=this->imag - getImag();
    Complex s =Complex(re,im);
    return s;
}

Complex Complex::operator-(double d)
{
    double re,im;
    re=this->real - d;
    im=this->imag - d;
    Complex s = Complex(re,im);
    return s;
}

Complex Complex::operator*(Complex c)
{
    double re,im;
    re = this->real* getReal() - this->imag*getImag();
    im = this->real* getImag() + this->imag*getReal();
    return (Complex (re,im));
}
    
Complex Complex::operator*(double d)
{
    return (Complex (this->real *d, this->imag *d));

}

Complex Complex::operator/(Complex c )
{
    if((getReal()==0)&& getImag()==0)
    {
        std::cout<<"Error. Division by zero";
    }
    else
    {
        double re,im;
        re=(this->real * getReal() + this->imag * getImag())/(getReal()*getReal() + getImag()*getImag());
        im=(this->imag * getReal() - this->real * getImag())/(getReal()*getReal() + getImag()*getImag());
        return (Complex(re,im));
    }
    return 0;
}

Complex Complex::operator/(double d)
{
    if (d==0)
    {
        std::cout<<"Error";
    }
    else
    {
        return (Complex(this->real/d, this->imag/d));
    }
}

//Operatori logici

bool Complex::operator<(Complex c)
{
    return ( (this->real*this->real + this->imag*this->imag) <  (getReal()*getReal()+getImag()*getImag()) );
}

bool Complex::operator<(double d)
{
    return ((this->real*this->real +this->imag*this->imag)<d*d);
}



double Complex::getReal()
{
    return ((*this).real);
}

double Complex::getImag()
{
    return ((*this).imag);
}

void Complex::setReal(double re)
{
    this->real=re;
}

void Complex::setImag(double im)
{
    this->imag=im;
}













